package UML;
import java.util.Date;

public class Online {

    class Product {
        private String title;
        private double weight;
        private String description;

        public Product(String title, double weight, String description) {
            this.title = title;
            this.weight = weight;
            this.description = description;
        }

        public double getPriceForQuantity(int quantity) {
            // 这里可以根据具体业务逻辑实现获取商品总价的方法
            return 0.0;
        }

        public double getWeight() {
            return weight;
        }

        public String getTitle() {
            return title;
        }

        public String getDescription() {
            return description;
        }
    }

    class OrderDetail {
        private int quantity;
        private Product product;

        public OrderDetail(int quantity, Product product) {
            this.quantity = quantity;
            this.product = product;
        }

        public double calculateSubTotal() {
            return product.getPriceForQuantity(quantity);
        }

        public double calculateWeight() {
            return quantity * product.getWeight();
        }
    }

    class Payment {
        private double amount;

        public Payment(double amount) {
            this.amount = amount;
        }

        public double getAmount() {
            return amount;
        }
    }

    class Credit extends Payment {
        private String number;
        private String type;
        private Date expireDate;

        public Credit(double amount, String number, String type, Date expireDate) {
            super(amount);
            this.number = number;
            this.type = type;
            this.expireDate = expireDate;
        }

        public String getNumber() {
            return number;
        }

        public String getType() {
            return type;
        }

        public Date getExpireDate() {
            return expireDate;
        }
    }

    class Cash extends Payment {
        private double cashTendered;

        public Cash(double amount, double cashTendered) {
            super(amount);
            this.cashTendered = cashTendered;
        }

        public double getCashTendered() {
            return cashTendered;
        }
    }

    class WireTransfer extends Payment {
        private String bankID;
        private String bankName;

        public WireTransfer(double amount, String bankID, String bankName) {
            super(amount);
            this.bankID = bankID;
            this.bankName = bankName;
        }

        public String getBankID() {
            return bankID;
        }

        public String getBankName() {
            return bankName;
        }
    }

    class AliPay extends Payment {
        private String number;

        public AliPay(double amount, String number) {
            super(amount);
            this.number = number;
        }

        public String getNumber() {
            return number;
        }
    }

    class WeixinPay extends Payment {
        private String number;

        public WeixinPay(double amount, String number) {
            super(amount);
            this.number = number;
        }

        public String getNumber() {
            return number;
        }
    }

    class Order {
        private Date createDate;
        private String status;
        private OrderDetail[] orderDetails;
        private Payment payment;

        public Order(Date createDate, String status) {
            this.createDate = createDate;
            this.status = status;
            this.orderDetails = new OrderDetail[0];
        }

        public void addOrderDetail(OrderDetail orderDetail) {
            OrderDetail[] newOrderDetails = new OrderDetail[orderDetails.length + 1];
            System.arraycopy(orderDetails, 0, newOrderDetails, 0, orderDetails.length);
            newOrderDetails[orderDetails.length] = orderDetail;
            orderDetails = newOrderDetails;
        }

        public void setPayment(Payment payment) {
            this.payment = payment;
        }

        public Date getCreateDate() {
            return createDate;
        }

        public String getStatus() {
            return status;
        }

        public OrderDetail[] getOrderDetails() {
            return orderDetails;
        }

        public Payment getPayment() {
            return payment;
        }
    }

    class Customer {
        private String name;
        private String contact;
        private String deliveryAddress;
        private boolean active;
        private Order[] orders;

        public Customer(String name, String contact, String deliveryAddress, boolean active) {
            this.name = name;
            this.contact = contact;
            this.deliveryAddress = deliveryAddress;
            this.active = active;
            this.orders = new Order[0];
        }

        public void addOrder(Order order) {
            Order[] newOrders = new Order[orders.length + 1];
            System.arraycopy(orders, 0, newOrders, 0, orders.length);
            newOrders[orders.length] = order;
            orders = newOrders;
        }

        public String getName() {
            return name;
        }

        public String getContact() {
            return contact;
        }

        public String getDeliveryAddress() {
            return deliveryAddress;
        }

        public boolean isActive() {
            return active;
        }

        public Order[] getOrders() {
            return orders;
        }
    }
}